"use strict";
// pages/meeting/detail.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    path: '',
    filename: '',
    path_toy: '',
    filename_toy: '',
    nowdate:'2019-11-14',
    endcopydate:'2019-11-14',
    fromcutdate:'2019-11-14',
    tocutdate:'2019-11-14',
    covered:true,
    accounts: ["-选择-","复制到", "删除区间","剪切到"],
    accountIndex: 0
  },

  refrash:function(){
    app.api.api_meeting_upload_cfg().then(res => {
      this.setData({
        nowdate: res.nowdate,
        endcopydate: res.endcopydate,
        fromcutdate: res.fromcutdate,
        tocutdate: res.tocutdate
      })
    });
  },

  upload:function(){
    var that = this
    wx.chooseMessageFile({
      count: 1,     //能选择文件的数量
      type: 'file',   //能选择文件的类型,我这里只允许上传文件.还有视频,图片,或者都可以
      success(res) {
        var size = res.tempFiles[0].size;
        var filename = res.tempFiles[0].name;
        var newfilename = filename + "";

        if (size > 4194304 || newfilename.indexOf(".xlsx") == -1) { //我还限制了文件的大小和具体文件类型
          wx.showToast({
            title: '文件大小不能超过4MB,格式必须为xlsx！',
            icon: "none",
            duration: 2000,
            mask: true
          })
        } else {
          that.setData({
            path: res.tempFiles[0].path, //将文件的路径保存在页面的变量上,方便 wx.uploadFile调用
            filename: filename              //渲染到wxml方便用户知道自己选择了什么文件
          })
        }
      }
    })
  },
  upload_toy:function(){
    var that = this
    wx.chooseMessageFile({
      count: 1,     //能选择文件的数量
      type: 'file',   //能选择文件的类型,我这里只允许上传文件.还有视频,图片,或者都可以
      success(res) {
        var size = res.tempFiles[0].size;
        var filename = res.tempFiles[0].name;
        var newfilename = filename + "";

        if (size > 4194304 || newfilename.indexOf(".xlsx") == -1) { //我还限制了文件的大小和具体文件类型
          wx.showToast({
            title: '文件大小不能超过4MB,格式必须为xlsx！',
            icon: "none",
            duration: 2000,
            mask: true
          })
        } else {
          that.setData({
            path_toy: res.tempFiles[0].path, //将文件的路径保存在页面的变量上,方便 wx.uploadFile调用
            filename_toy: filename              //渲染到wxml方便用户知道自己选择了什么文件
          })
        }
      }
    })
  },
  uploadshow_toy: function () {
    wx.navigateTo({
      url: 'uploadshow_toy'
    })
  },
  submitFile_toy:function(){
    var param = {};
    param = this.data;
    var filedata = [];
    filedata[0] = this.data.path_toy; 
    app.api.api_toy_upload(filedata,param,function(res){
      wx.showToast({
        title: JSON.parse(res.data).message,
        icon: '',
        mask: true,
        duration: 1500
      })  
    })
  },
  bindDateChange: function (e) {
    var varobj = {}
    varobj[e.target.id] = e.detail.value
    this.setData(varobj)
  },
  bindAccountChange: function (e) {
    console.log('picker account 发生选择改变，携带值为', e.detail.value);
    this.setData({
      accountIndex: e.detail.value
    })
  },
  bindSwitchChange:function(e){
    this.setData({
      covered: e.detail.value
    })
  },
  cutclass:function(){
    var param = {};
    param = this.data;
    param['covered'] = this.data.covered + '';
    var filedata = [];
    filedata[0] = this.data.path;
    app.api.api_meeting_upload_classdeal(param).then(res => {
      wx.showToast({
        title: '成功',
        icon: '',
        mask: true,
        duration: 1500
      })  
    });
  },
  submitFile:function(){
    var param = {};
    param = this.data;
    param['covered'] = this.data.covered+'';
    var filedata = [];
    filedata[0] = this.data.path; 
    app.api.api_meeting_upload(filedata,param,function(res){
      wx.showToast({
        title: JSON.parse(res.data).message,
        icon: '',
        mask: true,
        duration: 1500
      })  
    })
  },
  uploadshow: function () {
    wx.navigateTo({
      url: 'uploadshow'
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.refrash()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    let title = '会议'
    if (this.data.info.name){
      title += " - " + this.data.info.name
    }
    return {
      title: title,
      page: '/pages/meeting/detail?meeting_id='+this.data.meeting_id
    }
  }
})